package com.haibei.utils;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.common.uitl.StringUtils;
import com.haibei.net.NetInterface;

public class RichBoxTool {


	private static String getMidContnet(String mid){
		 return mid.substring(7, mid.length()-8);
	}
	
	private static String  coverImgNode(String str){
		if(!StringUtils.isEmpty(str)){
			Pattern patrn=Pattern.compile("<<img>>([^<]+?)<</img>>");
			Matcher match = patrn.matcher(str);
			while(match.find()){
				String ret=match.group();
				String content=getMidContnet(ret);
				str=str.replace("<<img>>"+content+"<</img>>", "<img src="+NetInterface.img_host+content+">");
			}
		}
		return str;
	}
	
	public static String toHtmlFromRichText(String richText) {

		String result = richText.replace("<<u>>", "<u>");
		result = result.replace("<</u>>", "</u>");
		
		result = result.replace("<<br/>>", "<br/>");
		
		result = result.replace("<<b>>", "<b>");
		result = result.replace("<</b>>", "</b>");
		
		result = result.replace("<<i>>", "<i>");
		result = result.replace("<</i>>", "</i>");
		
		result = result.replace("<<red>>", "<font color=\"red\">");
		result = result.replace("<</red>>", "</font>");
		
		result = result.replace("<<blue>>", "<font color=\"blue\">");
		result = result.replace("<</blue>>", "</font>");
		
		result = result.replace("<<yellow>>", "<font color=\"yellow\">");
		result = result.replace("<</yellow>>", "</font>");
		
		result = result.replace("<<green>>", "<font color=\"green\">");
		result = result.replace("<</green>>", "</font>");

		result = result.replace("<<gray>>", "<font color=\"gray\">");
		result = result.replace("<</gray>>", "</font>");
		
		result = result.replace("<<purple>>", "<font color=\"purple\">");
		result = result.replace("<</purple>>", "</font>");
		
		result = result.replace("<<orange>>", "<font color=\"orange\">");
		result = result.replace("<</orange>>", "</font>");
		
		result = result.replace("<<pink>>", "<font color=\"pink\">");
		result = result.replace("<</pink>>", "</font>");
		return result;
	}
}
